package course10;

import java.text.DecimalFormat;

public class ShuZu {
    public static void main(String[] args) {

        int[] list = {1, 2, 3, 4, 5};
        //System.out.println(list[0]);

        int size = 5;

        //把数组一个一个的输入
        double[] myList = new double[size];
        myList[0] = 5.6;
        myList[1] = 4.5;
        myList[2] = 3.3;
        myList[3] = 13.2;
        myList[4] = 4.67;

        double total = 0;

        for (int i = 0; i < size; i++) {
            total += myList[i];
        }

        System.out.println("总和为：" + total);

        //保留两位小数，实例化DecimalFormat类，然后调用其中的format方法
        DecimalFormat d = new DecimalFormat("#.0");
        System.out.println("The total is:" + d.format(total));

        //遍历
       /* for (int i = 0; i < myList.length; i++) {
            System.out.println(myList[i]);
        }*/
        // for each 遍历
        //  for (double a : myList) {
        //     System.out.println(a);


        //二维数组
        double[][] myList1 = new double[2][];
        myList1[0] = new double[2];
        myList1[1] = new double[3];

        myList1[0][0] = 1;
        myList1[0][1] = 2;

        //用两个for循环将二维数组输出
           /* for (int i = 0; i < myList1.length; i++) {
                double[] a = myList1[i];  //先拖出每个二维数组元素，即2个一维数组。

                for (int j = 0; j < a.length; j++) {
                    System.out.print(a[j]+" ");    //再对每个一维数组进行遍历
                }

                for (int k = 0; k < 3; k++) {
                    System.out.println();        // 多重回车换行
                }
            }*/

        //使用for each循环
        for (double[] ns : myList1) {    // ns的类型是myList1的元素类型

            for (double n : ns) {   //n的类型都是ns的元素类型
                System.out.print(n);
                System.out.print("    ");
            }
            System.out.println();
        }//参见onenote廖雪峰java那块笔记





/*
            for (int i = 0; i < myList1[0].length; i++) {
                System.out.println(myList1[0][i]);
            }

            for (int i = 0; i < myList1[1].length; i++) {
                System.out.println(myList1[1][i]);
            }
*/


        //定义一个double类型的数组，有五个元素，找出最大的元素
        double[] array = {3, 1, 4, 5, 9};
        double c = 0;

        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] < array[j]) {
                    array[i] = array[j];
                }
                c = array[i];
            }
        }
        System.out.println("The biggest one is: " + c);
    }
}